<?php $this->load->view('common/admin_header');?>
<link rel="stylesheet" type="text/css" href="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.css')?>" media="screen" />
<script type="text/javascript" src="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.pack.js')?>"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
  $("#thumbnail").fancybox({
      helpers:{title:{type:'float'}}
  });
});
</script>
<div class="block">
  <div class="block_head">
    <div class="bheadl"></div>
    <div class="bheadr"></div>
    <h2><?=$lang['settings_lable_1']?></h2>
      <ul class="tabs">
        <li><a href="#website"><?=$lang['settings_lable_11']?></a></li>
        <li><a href="#config"><?=$lang['settings_lable_24']?></a></li>
        <li><a href="#other"><?=$lang['settings_lable_35']?></a></li>
      </ul>
  </div>
  <?php $google_map_exists=false;?>
  <!-- .block_head ends -->
    <form id="form" action="<?=site_url('admins/settings/edit');?>" method="post" enctype="multipart/form-data">
        <?php foreach($lists as $key=>$arr):?>
      <div class="tab_content block_content" id="<?=$key?>">
      <?php $this->load->view('common/notify');?>
        <input type="hidden" name="settings[]" value="<?=$key?>">
        <?php foreach($arr as $v):?>
        <p>
           <?php if($getlang=='zh-tw'){?>
          <?php if(!in_array($v['key'],array('website_count','sms_count','default_time'))):?>
          <label><?=$v['description']?>:</label>
          <?php endif;?>
           <?php }else{?>
            <?php if(!in_array($v['key'],array('website_count','sms_count','default_time'))):?>
                <label><?=$v['content']?>:</label>
            <?php endif;?>
            <?php };?>


          <input type="hidden" name='<?=$key.'_key';?>[]' value="<?=$v['key']?>">
          <input type="hidden" name='<?=$v['key'].'_description';?>' value="<?=$v['description']?>">
          <input type="hidden" name='<?=$v['key'].'_content';?>' value="<?=$v['content']?>">
          <!--網站統計 隱藏值-->
          <?php if(in_array($v['key'],array('website_count','sms_count','default_time'))):?>
          <input type="hidden" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>
          <!--網站標題-->
          <?php if($v['key']=='title'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>
            <!--網站標題-->
            <?php if($v['key']=='entitle'):?>
                <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
            <?php endif;?>
            <!--logo-->
            <?php if($v['key'] == 'website_logo'):?>
              <p>
                <a id="thumbnail" href="<?=base_url($v['value'])?>" class="thumbnail">
                  <img id="img_images" src="<?php echo empty($v['value']) ? base_url('/themes/admins/img/no_image.png') : base_url(imagelib::resize_thumb($v['value'],260,260)); ?>" class="preview-img" style="max-width:300px">
                </a>
              </p>
              <p>
            <div id="simple-btn" data-tag="display_logo" class="btn btn-success js-fileapi-wrapper">
               <div class="js-browse">
                  <input type="file" name="Filedata">
               </div>
               <div class="js-upload" style="display: none">
                  <div class="progress progress-success">
                    <div class="js-progress bar"></div>
                  </div>
                  <span class="btn-txt">Uploading (<span class="js-size"></span>)</span>
               </div>
            </div>
            <input id="old_images" type="hidden" name="<?=$v['key'].'_value';?>" value="<?=$v['value'];?>">
            </p>
          <?php endif;?>
          <!--網站關鍵字-->
          <?php if($v['key']=='keyword'):?>
          <input type="text" id="tags_1" class="text small tags" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>
          <?php if($v['key']=='description'):?>
          <textarea name="<?=$v['key'].'_value';?>"><?=$v['value']?></textarea>
          <?php endif;?>          
          <!--網站是否運行-->
          <?php if($v['key']=='website_status'):?>
          <input type="radio" class="radio" name="<?=$v['key'].'_value';?>" value="1" <?=$v['value']==1?'checked':''?>/>
          <span>是</span>
          <input type="radio" class="radio" name="<?=$v['key'].'_value';?>" value="2" <?=$v['value']==2?'checked':''?> />
          <span>否</span>
          <?php endif;?>

          <!--操作日誌保留多少天-->
          <?php if($v['key']=='operator_log' || $v['key']=='movie_link'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>"> <span><?=$lang['settings_lable_3']?></span>
          <?php endif;?>

          <!--網站版權-->
          <?php if($v['key']=='copyright'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>

          <!--電話號碼-->
          <?php if($v['key']=='telephone'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>

          <!--地圖maps-->
          <?php if($v['key']=='google_maps'):?>
          <?php $google_map_exists=true;?>
          <input id="addresspicker_map" class="text small" />
          <div id="my_map_canvas" style="width:90%; height:380px; border:1px solid #DDD;"></div><br/>
          <input type="hidden" id="locality" disabled=disabled>
          <input type="hidden" id="country" disabled=disabled>
          <input type="hidden" id="types" disabled=disabled />
          <input type="hidden" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php $google_maps=!empty($v['value'])?explode('|',$v['value']):'';?>
          <input type="hidden" id="map_x" name="map_x" value="<?=!empty($google_maps) && count($google_maps)==2?$google_maps[0]:''?>">
          <input type="hidden" id="map_y" name="map_y" value="<?=!empty($google_maps) && count($google_maps)==2?$google_maps[1]:''?>">
          <?php endif;?>

          <!--網站語言-->
         <!-- <?php /*if($v['key']=='default_language'):*/?>
          <select name="<?/*=$v['key'].'_value';*/?>" id="lang_type" >
            <?php /*foreach($language_query->result_array() as $lag):*/?>
            <option value="<?/*=$lag['id']*/?>" <?/*=$v['value']==$lag['id']?'selected':''*/?> >
                --<?/*=$lag['name']*/?>--
            </option>

            <?php /*endforeach;*/?>
          </select>
          --><?php /*endif;*/?>

          <!--時間格式-->
          <?php if($v['key']=='default_front_time'):?>
            <select id="format_time" name="<?=$v['key'].'_value';?>">
              <option value="Y/m/d" <?=$v['value']=='Y/m/d'?'selected':''?>><?=date('Y/m/d')?></option>
              <option value="Y/m/d H:i" <?=$v['value']=='Y/m/d H:i'?'selected':''?>><?=date('Y/m/d H:i')?></option>
              <option value="Y/m/d H:i:s" <?=$v['value']=='Y/m/d H:i:s'?'selected':''?>><?=date('Y/m/d H:i:s')?></option>
              <option value="Y-m-d" <?=$v['value']=='Y-m-d'?'selected':''?>><?=date('Y-m-d')?></option>
              <option value="Y-m-d H:i" <?=$v['value']=='Y-m-d H:i'?'selected':''?>><?=date('Y-m-d H:i')?></option>
              <option value="Y-m-d H:i:s" <?=$v['value']=='Y-m-d H:i:s'?'selected':''?>><?=date('Y-m-d H:i:s')?></option>
            </select>
          <?php endif;?>

          <!--列表個數啓用-->
          <?php if($v['key']=='default_admin_limit' ||  $v['key']=='default_front_limit'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>

          <!--Email接收者-->
          <?php if($v['key']=='email_to'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <span class="note required"><?=$lang['settings_lable_16']?> </span>
          <?php endif;?>  
          <!--email發送方法-->
          <?php if($v['key']=='default_email_type'):?>
          <select id="mail_type" name="<?=$v['key'].'_value';?>">
            <option value="1" <?=$v['value']=='1'?'selected':''?>>MAIL</option>
            <option value="2" <?=$v['value']=='2'?'selected':''?>>STMP</option>
          </select>
          <?php endif;?>  
          <!-- Email發出者: -->
          <?php if($v['key']=='email_host'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <span class="note required"><?=$lang['settings_lable_19']?></span>
          <?php endif;?>
          <!-- 發出Email的名字: -->
          <?php if($v['key']=='email_form'):?>
          <input type="text" mail_type="mail" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <span class="note required"><?=$lang['settings_lable_36']?></span>
          <?php endif;?>
          <!-- smtp地址 -->
          <?php if($v['key']=='smtp_host'):?>
          <input type="text" mail_type="smtp" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <span class="note required"><?=$lang['settings_lable_20']?></span>
          <?php endif;?>
          <!-- 賬戶密碼 -->
          <?php if($v['key']=='smtp_password'):?>
          <input type="password" mail_type="smtp" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <span class="note required"><?=$lang['settings_lable_21']?></span>
          <?php endif;?>
          <!-- 服務器端口 -->
          <?php if($v['key']=='smtp_port'):?>
          <input type="text" mail_type="smtp" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <span class="note required"><?=$lang['settings_lable_22']?></span>
          <?php endif;?>


          <!--判斷是否是自定義配置-->

          <!--網站聯絡我們-->
          <?php if(in_array($v['key'],array('front_contact1','front_contact2~~','front_contact3~~'))):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>

          <!--網站活動簡介-->
          <?php if(in_array($v['key'],array('front_about'))):?>
          <textarea name="<?=$v['key'].'_value';?>"><?=$v['value']?></textarea>
          <?php endif;?>
          
          <!--是否營業-->
          <?php if($v['key']=='shop_status' || $v['key']=='integral_status'):?>
          <input type="radio" class="radio" name="<?=$v['key'].'_value';?>" value="1" <?=$v['value']==1?'checked':''?>/>
          <span><?=$lang['settings_lable_5']?></span>
          <input type="radio" class="radio" name="<?=$v['key'].'_value';?>" value="2" <?=$v['value']==2?'checked':''?> />
          <span><?=$lang['settings_lable_6']?></span>
          <?php endif;?>
          
          <!--展廳營業提示-->
          <?php if(in_array($v['key'],array('shop_close'))):?>
          <textarea name="<?=$v['key'].'_value';?>"><?=$v['value']?></textarea>
          <?php endif;?>
  

          <!--是否開啟短信通知-->
          <?php if($v['key']=='sms_status'):?>
          <input type="radio" class="radio" name="<?=$v['key'].'_value';?>" value="1" <?=$v['value']==1?'checked':''?>/>
          <span><?=$lang['settings_lable_5']?></span>
          <input type="radio" class="radio" name="<?=$v['key'].'_value';?>" value="2" <?=$v['value']==2?'checked':''?> />
          <span><?=$lang['settings_lable_6']?></span>
          <?php endif;?>

          <!--打印機-->
          <?php if($v['key']=='printname'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>
          <?php if($v['key']=='printkey'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>

          <!--短信剩餘條數不夠,則提示-->
          <?php if($v['key']=='sms_remind'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>

          <?php if($this->nsession->userdata('nick_name')=='clickr'):?>
            <!--店主是否開啟短信通知-->
            <?php if($v['key']=='sms_shop_status'):?>
            <input type="radio" class="radio" name="<?=$v['key'].'_value';?>" value="1" <?=$v['value']==1?'checked':''?>/>
            <span>SIM卡短信模式</span>
            <input type="radio" class="radio" name="<?=$v['key'].'_value';?>" value="2" <?=$v['value']==2?'checked':''?> />
            <span>WIFI HTTP模式</span>
            <?php endif;?>

            <!--店主打印機sim卡號碼-->
            <?php if($v['key']=='sms_shop_phone'):?>
            <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
            <span class="note required">必須為澳門移動電話號碼。</span>
            <?php endif;?>

            <!--打印機IMEI號-->
            <?php if($v['key']=='print_imei'):?>
            <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
            <span class="note required">WIFI HTTP模式下輸入打印機的IMEI號碼</span>
            <?php endif;?>
          <?php endif;?>
          <!--網站google analytics-->
          <?php if($v['key']=='front_google_analytics'):?>
          <input type="text" class="text small" name='<?=$v['key'].'_value';?>' value="<?=$v['value']?>">
          <?php endif;?>

        <?php endforeach;?>
        <p>
          <input class="btn btn-primary" type="submit" name="btn_save" value="<?=$lang['global_lable_12']?>" />
          <input class="btn" type="reset" value="<?=$lang['global_lable_13']?>"/>
        </p>
      </div><!-- .block_content ends -->
      <?php endforeach;?>
    </form>
  <!-- .block_content ends -->
  <div class="bendl"></div>
  <div class="bendr"></div>
</div>
<!-- .block ends -->
<?php if($google_map_exists):?>
<script src="http://maps.google.com/maps/api/js?sensor=false&language=zh_TW"></script>
<link rel="stylesheet" href="<?=base_url('themes/admins/js/addresspicker/base/jquery.ui.all.css')?>">
<script src="<?=base_url('themes/admins/js/addresspicker/jquery-ui-1.8.7.min.js')?>"></script>
<script src="<?=base_url('themes/admins/js/addresspicker/jquery.ui.addresspicker.js')?>"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
  var addresspickerMap = $( "#addresspicker_map" ).addresspicker({
    regionBias: "OMA",
    mapOptions: {zoom: 16},
    elements: {
      map:      "#my_map_canvas",
      lat:      "#map_x",
      lng:      "#map_y",
      locality: '#locality',
      country:  '#country',
      type:    '#types'
    }
  });
  var gmarker = addresspickerMap.addresspicker("marker");
  gmarker.setVisible(true);
  addresspickerMap.addresspicker( "updatePosition");
});
</script>
<?php endif;?>
<!--<script src="<?=base_url('themes/admins/js/jscolor/jscolor.js')?>"></script>顏色選擇-->
<link rel="stylesheet" href="<?=base_url('themes/admins/js/tagsinput/jquery.tagsinput.css')?>">
<script src="<?=base_url('themes/admins/js/tagsinput/jquery.tagsinput.min.js')?>"></script>
<script type="text/javascript" charset="utf-8">
$(function() {
  $('#tags_1').tagsInput({width:'auto',defaultText:'keyword'});//tags
});
</script>

<script type="text/javascript" charset="utf-8">
window.FileAPI = {
  debug: true, // debug mode
  cors: false,    // if used CORS, set `true`
  media: false,   // if used WebCam, set `true`
  flashUrl:"<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.flash.swf')?>",
  staticPath:'themes/admins/js/jquery.fileapi/FileAPI/' // path to *.swf
};
</script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.min.js')?>"></script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.exif.js')?>"></script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/jquery.fileapi.js')?>"></script>
<script type="text/javascript" charset="utf-8">
  $(document).ready(function($) {
    var folder=encodeURIComponent('uploads/news/');
    $('#simple-btn').fileapi({
       url:"<?=site_url('admins/upload/single_upload')?>",
       data: {'folder':folder,'_size':'180x180','_element_id':'front_adv2_img','_admin_id':"<?=$this->nsession->userdata('admin_id')?>",'_nickName':"<?=$this->nsession->userdata('nick_name')?>"},
       multiple: false,
       accept: 'image/*',
       maxSize: 2 * FileAPI.MB,
       autoUpload: true,
       clearOnComplete:true,
       elements: {
          size: '#simple-btn .js-size',
          active: { show: '#simple-btn .js-upload', hide: '#simple-btn .js-browse' },
          progress: '#simple-btn .js-progress'
       },
       onComplete:function(evt,uiEvt){
        var error = uiEvt.error;
        var result = uiEvt.result; // server response
        if(!error && result){
          // console.log(result);
          if(result.error){
            alert(result.error);
            return;
          }
          $("#old_images").val(result.img_path);
          $("#img_images").attr('src',result.thumb_img);
          if($('a[tag="'+result.element_id+'"]').length)
            $('a[tag="'+result.element_id+'"]').show();
        }
      }
    });

    $('#simple-btn2').fileapi({
       url:"<?=site_url('admins/upload/single_upload')?>",
       data: {'folder':folder,'_size':'180x180','_element_id':'front_adv3_img','_admin_id':"<?=$this->nsession->userdata('admin_id')?>",'_nickName':"<?=$this->nsession->userdata('nick_name')?>"},
       multiple: false,
       accept: 'image/*',
       maxSize: 2 * FileAPI.MB,
       autoUpload: true,
       clearOnComplete:true,
       elements: {
          size: '#simple-btn2 .js-size',
          active: { show: '#simple-btn2 .js-upload', hide: '#simple-btn2 .js-browse' },
          progress: '#simple-btn2 .js-progress'
       },
       onComplete:function(evt,uiEvt){
        var error = uiEvt.error;
        var result = uiEvt.result; // server response
        if(!error && result){
          // console.log(result);
          if(result.error){
            alert(result.error);
            return;
          }
          $("#old_"+result.element_id).val(result.img_path);
          $("#img_"+result.element_id).attr('src',result.thumb_img);
          if($('a[tag="'+result.element_id+'"]').length)
            $('a[tag="'+result.element_id+'"]').show();
        }
      }
    });

    //清除圖片
    $('a[href="#clear_img"]').click(function() {
      var obj=$(this);
      var action="<?=site_url('admins/upload/delete')?>";
      var defaule_img="<?=base_url('themes/admins/img/no_image.png')?>";
      clear_img(obj,action,defaule_img);
      return false;
    });

  });
</script>
<script>
  $(document).ready(function(){
    var mail_type=$("#mail_type").val();
    soh(mail_type);
    mail_test(mail_type);
    $('#mail_type').change(function(){
      mail_type=$("#mail_type").val();
      soh(mail_type);
    });
  });
  //隱藏顯示
  function soh(mail_type){
    if(mail_type==1){
      mail_test(mail_type)
      $("input[mail_type='mail']").parent().show();
      $("input[mail_type='smtp']").parent().hide();
    }else{
      mail_test(mail_type)
      $("input[mail_type='mail']").parent().hide();
      $("input[mail_type='smtp']").parent().show();
    }
  }
  function mail_test(mail_type){
    $("#mail_test").remove();
    var a='<p id="mail_test"><br ><a href="<?=site_url('admins/settings/mail_test')?>" target="_blank"><?php echo $lang['settings_lable_23']?></a></p>';
    if(mail_type==1){
      $("input[name='email_form_value']").parent().append(a);
    }else{
      $("input[name='smtp_port_value']").parent().append(a);
    }
  }
  $(document).ready(function(){
      var lang_type=$("#lang_type").val();
      $('#lang_type').change(function(){

          if(lang_type==1){
              window.location = location.pathname + '?lang=zh-tw';

          }else{
              window.location = location.pathname + '?lang=english';
          }


      });
  });

</script>
<?php $this->load->view('common/admin_footer');?>